﻿@model ExcellentCRM.DataService.Models.Department

@{
    Layout = null;
}

@using (Ajax.BeginForm("CreateOrUpdate", null, new AjaxOptions
    {
        HttpMethod = "post",
        OnSuccess = "saveSucc"
    },
    new {@class = "form-horizontal", id = "deptSaveForm"}))
{
    @Html.AntiForgeryToken()
    <div id="alertContain" class="alert alert-error fade in hide">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <div class="alert-content"></div>
    </div>
    <div class="control-group">
        @Html.LabelFor(m => m.DeptName, new { @class = "control-label" })
        <div class="controls">
            @Html.TextBoxFor(m => m.DeptName, null, new {placeholder = "部门名"})
            <span class="help-inline">
                @Html.ValidationMessageFor(m => m.DeptName)
            </span>
        </div>
    </div>
    <div class="control-group hidden">
        <div class="controls">
            <input type="submit" value="保存" class="btn btn-primary"/>
            @Html.HiddenFor(m => m.Id)
        </div>
    </div>
}
<script type="text/javascript">
    $(function () {
        $.validator.unobtrusive.parse('#deptSaveForm');
    });

    function saveSucc(result) {
        if (!result || (!result.success && !result.message)) {
            alert('保存失败，未知原因');
            return;
        }
        if (!result.success && result.message) {
            $('#alertContain .alert-content').html(result.message);
            $('#alertContain').removeClass('alert-success hide').addClass('alert-error').alert();
            return;
        }
        if (result.success) {
            $('#alertContain .alert-content').html('保存完成');
            $('#alertContain').removeClass('alert-error hide').addClass('alert-success').alert();
        }
    }
</script>